'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames2 = require('classnames');

var _classnames3 = _interopRequireDefault(_classnames2);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * Created by elly on 2017/4/8.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                */


var Option = function (_Component) {
    _inherits(Option, _Component);

    function Option(props) {
        _classCallCheck(this, Option);

        return _possibleConstructorReturn(this, (Option.__proto__ || Object.getPrototypeOf(Option)).call(this, props));
    }

    _createClass(Option, [{
        key: 'handleClick',
        value: function handleClick(e) {
            var _props = this.props,
                value = _props.value,
                disabled = _props.disabled,
                selected = _props.selected,
                onChange = _props.onChange,
                onDisableChange = _props.onDisableChange;

            if (disabled) {
                if (onDisableChange) onDisableChange(e, value);
            } else {
                onChange(e, value, !selected);
            }
        }
    }, {
        key: 'selectRender',
        value: function selectRender(selected, multiple) {
            if (multiple) {
                if (selected) {
                    return _react2['default'].createElement('span', { className: 'el-select-selected fa fa-check-square' });
                } else {
                    return _react2['default'].createElement('span', { className: 'el-select-unselected fa fa-square-o' });
                }
            } else {
                return selected ? _react2['default'].createElement('span', { className: 'el-select-selected fa fa-check' }) : null;
            }
        }
    }, {
        key: 'render',
        value: function render() {
            var _props2 = this.props,
                label = _props2.label,
                disabled = _props2.disabled,
                multiple = _props2.multiple,
                className = _props2.className,
                selected = _props2.selected;

            var _className = (0, _classnames3['default'])(_defineProperty({
                'el-disabled': disabled
            }, className, !!className));
            return _react2['default'].createElement(
                'li',
                { className: _className,
                    'aria-disabled': disabled ? 'disabled' : '',
                    'aria-selected': selected ? 'selected' : 'unselected',
                    onClick: this.handleClick.bind(this) },
                label,
                this.selectRender(selected, multiple)
            );
        }
    }]);

    return Option;
}(_react.Component);

exports['default'] = Option;


Option.propTypes = {};

Option.defaultProps = {
    className: ""
};